package com.kvest.fragmentsfinaltest.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.kvest.fragmentsfinaltest.R;

/**
 * Created with IntelliJ IDEA.
 * User: Kvest
 * Date: 25.03.13
 * Time: 21:26
 * To change this template use File | Settings | File Templates.
 */
public class AboutFragment extends Fragment implements View.OnClickListener {
    public static final String TEXT_ARGUMENT = "text";
    private OnNextListener listener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.about_fragment_layout, null);
        ((TextView)view.findViewById(R.id.content_tv)).setText(getText());
        view.findViewById(R.id.next_btn).setOnClickListener(this);

        return view;
    }

    private String getText() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            if (arguments.containsKey(TEXT_ARGUMENT)) {
                return arguments.getString(TEXT_ARGUMENT);
            } else {
                return "No test argument";
            }
        } else {
            return "No arguments";
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        try {
            listener = (OnNextListener) activity;
        } catch (ClassCastException classCastException) {}
    }

    @Override
    public void onClick(View view) {
        if (listener != null) {
            listener.onNext();
        }
    }

    public interface OnNextListener {
        public void onNext();
    }
}
